<?
global $db;

$e = $db->query1("select * from node where id = ".$db->sqlint($params["id"]));

skin_param("page",$e);

if ($e["content"]) echo "<div>{$e["content"]}</div>";

function _map_link($e) {
	if ($e["link"]) $uri = "../{$e["link"]}";
	else $uri = "../{$e["id"]}";
	if ($e["uri"]) $uri = $e["uri"];
	$href = " href=\"$uri\" ";
	if ($e["target"]) $href.=" target='{$e["target"]}' ";
	$href.=" title=\"".htmlentities($e["title"])."\" ";
	return $href;
	}
	

function _map_tree($where) {
	global $db;
	
	$more = array();
	foreach ($db->query("select * from node where $where and hidden = 0 order by orders") as $e) $more[$e["parentid"]][]=$e;
	
	$r = array();
	$top = 0;
	if (!isset($more[$top])) return $r;
	
	$out=array_reverse($more[$top]);
	while (count($out)) {
        	$e=array_pop($out);
		$e["level"] = intval($e["level"]);
        	if (isset($more[$e["id"]])) {
			$a = array_reverse($more[$e["id"]]);
			foreach ($a as $k=>$ee) $a[$k]["level"] = $e["level"]+1;
			array_splice($out,count($out),0,$a);
			}
		$r[] = $e;
		}
	return $r;
	}

$where = "folder = 0 and folderid = ".$db->sqlint($e["folderid"]);	
$r = _map_tree($where);

echo "<div><p>";
$admin = $params["admin"];
foreach ($r as $ee) {
	echo str_repeat("&nbsp",$ee["level"]*4)."<a "._map_link($ee).">{$ee["name"]}</a>";
#	if ($admin) echo " <a href='skin-{$ee["skin_id"]}/edit.php'>edit skin</a>";
	echo "<br>";
	}

echo "</p></div>";	
?>